const express = require('express');
const router = express.Router();
const mysql = require('mysql2');
const { db } = require('../config');
const pool = mysql.createPool(db);

// 管理员登录接口
router.post('/login', (req, res) => {
  const { username, password } = req.body;
  pool.query(
    'SELECT * FROM admin WHERE username = ? AND password = ?',
    [username, password],
    (err, results) => {
      if (err) return res.status(500).json({ code: 1, message: '数据库错误' });
      if (results.length > 0) {
        res.json({ code: 0, message: '登录成功', admin: results[0] });
      } else {
        res.json({ code: 1, message: '用户名或密码错误' });
      }
    }
  );
});

module.exports = router; 